<% content_for :content do %>

  <!-- widget grid -->
  <section id="widget-grid" class="">
    <% if current_admin.can?(controller: "admin/terminal_orders", action: "new") %>
    <div class="row">
      <div class="col-sm-12">
        <div class="well">
          <%= form_tag import_admin_terminal_orders_path, :multipart => true , class: "form-inline" do %>
          <div class="form-group">
            <div>
              <%= file_field_tag "file", class: "btn btn-default btn-sm form-control" %>
            </div>
          </div>
          <%= hidden_field_tag :terminal_group_id,@terminal_group.id %>
          <%= submit_tag "工单导入", class: "btn btn-default" %>
          <% end %>
        </div>
      </div>
    </div>
    <% end %>
    <!-- row -->
    <div class="row">
      <!-- NEW WIDGET START -->
      <article class="col-xs-12 col-sm-12 col-md-12 col-lg-12">

        <% if flash[:success].present? %>
          <div class="alert alert-success fade in">
            <button class="close" data-dismiss="alert">
              ×
            </button>
            <i class="fa-fw fa fa-check"></i>
            <strong>成功</strong> <%= flash[:success] %>
          </div>
        <% elsif flash[:error].present? %>
          <div class="alert alert-danger fade in">
            <button class="close" data-dismiss="alert">
              ×
            </button>
            <i class="fa-fw fa fa-times"></i>
            <strong>错误!</strong> <%= flash[:error] %>
          </div>
        <% end %>

        <!-- Widget ID (each widget will need unique ID)-->
        <div class="jarviswidget jarviswidget-color-blueDark" id="wid-id-3" data-widget-editbutton="false" data-widget-colorbutton="false" data-widget-deletebutton="false">
          <!-- widget options:
          usage: <div class="jarviswidget" id="wid-id-0" data-widget-editbutton="false">
  
          data-widget-colorbutton="false"
          data-widget-editbutton="false"
          data-widget-togglebutton="false"
          data-widget-deletebutton="false"
          data-widget-fullscreenbutton="false"
          data-widget-custombutton="false"
          data-widget-collapsed="true"
          data-widget-sortable="false"
  
          -->
          <header>
            <span class="widget-icon"> <i class="fa fa-table"></i> </span>
            <h2>终端列表</h2>
  
          </header>
  
          <!-- widget div-->
          <div>
  
            <!-- widget edit box -->
            <div class="jarviswidget-editbox">
              <!-- This area used as dropdown edit box -->
  
            </div>
            <!-- end widget edit box -->
  
            <!-- widget content -->
            <div class="widget-body no-padding">
              <div class="widget-body-toolbar">
              </div>
              <table id="datatable_tabletools" class="table table-striped table-hover vertical-align-middle">
                <thead>
                  <tr>
                    <th>设备组</th>
                    <th>型号</th>
                    <th>地址/车牌</th>
                    <th>mac地址</th>  
                    <th>终端版本号</th>
                    <th>注册</th>
                    <th>签到数</th>
                    <th>3G剩余流量</th>
                    <th>操作</th>
                  </tr>
                </thead>
                <tbody>
                  <% @terminals.each do |r| %>
                    <tr id='order-<%= r.id %>'>
                      <td><%= r.terminal_group.try(:group_name) %></td>
                      <td>
                        <%= r.dispaly_order_name %>
                      </td>
                      <td><%= r.dispaly_address %></td>
                      <td>
                        <%= r.mac %>
                      </td>
                      <td>
                        <%= r.version %>
                      </td>
                      <td>
                        <%= r.total_register %>
                      </td>
                      <td><%= r.total_account_signin %></td>
                      <td><%= traffics_friendly_format r.left_traffic %></td>
                      <td><%= (link_to('编辑',edit_admin_terminal_order_path(r.terminal_order), remote: true) if r.terminal_order) if current_admin.can?(controller: "admin/terminal_orders", action: "edit") %>
                        <%= (link_to '移除', remove_admin_terminal_path(r), remote: true, confirm: '是否确定移除?', method: :post) if current_admin.can?(controller: "admin/terminal_groups", action: "edit") %>
                      </td>
                    </tr>
                  <% end %>
                </tbody>
              </table>
  
            </div>
            <!-- end widget content -->
  
          </div>
          <!-- end widget div -->
  
        </div>
        <!-- end widget -->
  
      </article>
      <!-- WIDGET END -->
  
    </div>
  
    <!-- end row -->
  
  </section>
  <!-- end widget grid -->
<% end %>

<% content_for :js do %>

  <script type="text/javascript">
  
    // DO NOT REMOVE : GLOBAL FUNCTIONS!
    
    $(document).ready(function() {
      
      /* TABLE TOOLS */
      $('#datatable_tabletools').dataTable({
        "sDom" : "<'dt-top-row'Tlf>r<'dt-wrapper't><'dt-row dt-bottom-row'<'row'<'col-sm-6'i><'col-sm-6 text-right'p>>",
        "oTableTools" : {
          "aButtons" : [ 
              <% if current_admin.can?(controller: "admin/terminal_orders", action: "new") %>
              {
                "sExtends":    "text",
                "sButtonText": '<%= link_to "添加设备", new_admin_terminal_order_path(terminal_group_id: @terminal_group.id), :remote => true %>'
              },
              <% end %>
              {
                "sExtends":    "text",
                "sButtonText": '<%= link_to "导出模板",export_admin_terminal_orders_path({format: :csv}.merge!(params)) %>'
              }
           ],
        },
        "bInfo": true,
        "fnInitComplete" : function(oSettings, json) {
          $(this).closest('#dt_table_tools_wrapper').find('.DTTT.btn-group').addClass('table_tools_group').children('a.btn').each(function() {
            $(this).addClass('btn-sm btn-default');
          });
        }
      });

    })

  </script>

<% end %>